package com.service;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;

import com.dao.MemberDao;
import com.model.Member;

@Service("memberService")
@Transactional
public class MemberServiceImpl implements MemberService {

	@Autowired
	private MemberDao memberDao;
	
	
	public void add(String branch,Member member) {
		memberDao.add(branch,member);		
	}

	public Member get(Integer id) {
		return memberDao.get(id);
	}

	public void delete(Integer id) {
		memberDao.delete(id);

	}

	public List<Member> getByFields(HttpServletRequest request,String name)
	{
		Integer id=0;
		String ticket="";
		Date from=null,to=null;
		try{
			if(request.getParameter("id").toString()!=null)
			id=Integer.parseInt(request.getParameter("id"));
		}catch(Exception e)
		{
			id=0;
		}
		try
		{
			if(request.getParameter("ticket").toString()!=null)
			ticket=request.getParameter("ticket");
		}
		catch(Exception e)
		{
			ticket="";
		}
		//from=request.getParameter("from");
		//to=request.getParameter("to");
		
		return memberDao.getByFields(id,ticket,from, to,name);
	}


	public List<Member> getAll(int page) {
		return memberDao.getAll(page);

	}

	public int getNoOfRecords() {
		return memberDao.getNoOfRecords();
	}

	@Override
	public List<Member> getAllForUser(String name) {
		
		return memberDao.getAllForUser(name);
	}

	@Override
	public List<Member> getAllForAdmin() {
		return memberDao.getAllForAdmin();
	}
}
